﻿using AJWPFAdmin.Core;
using AJWPFAdmin.Core.Components.AJTable.ViewModels;
using AJWPFAdmin.Core.Components.Views;
using AJWPFAdmin.Core.Excel;
using AJWPFAdmin.Core.ExtensionMethods;
using AJWPFAdmin.Core.Models;
using AJWPFAdmin.Core.Models.EF.Tables;
using AJWPFAdmin.Core.Mvvm;
using AJWPFAdmin.Core.Utils;
using AJWPFAdmin.Services.EF;
using MaterialDesignExtensions.Controls;
using MaterialDesignThemes.Wpf;
using Microsoft.AspNetCore.Mvc;
using Prism.Commands;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using AJWPFAdmin.Core.Excel;
using AJWPFAdmin.Core.Components.AJFilePicker.ViewModels;

namespace AJWPFAdmin.Modules.Common.ViewModels
{


    public class ImageShowCaseDialogViewModel : ViewModelBase, IDialogAware
    {
        private ObservableCollection<UploadFileItem> _images;
        public ObservableCollection<UploadFileItem> Images
        {
            get
            {
                return _images;
            }
            set
            {
                SetProperty(ref _images, value);
            }
        }



        private UploadConfig _options;
        public UploadConfig Options
        {
            get
            {
                return _options;
            }
            set
            {
                SetProperty(ref _options, value);
            }
        }

        public event Action<IDialogResult> RequestClose;

        public string Title => "图片预览";

        public ImageShowCaseDialogViewModel()
        {
            Options = new UploadConfig
            {
                Height = 200,
                Width = 200,
            };
            Images = new ObservableCollection<UploadFileItem>();
        }

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {

        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            parameters.TryGetValue<string>("data", out var jsonStr);
            var array = CommonUtil.TryGetJSONObject<string[]>(jsonStr) ?? Array.Empty<string>();
            Images.AddRange(array.Select(p => new UploadFileItem(p)));
        }
    }
}
